package com.ruoyi.student.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.student.domain.StudentBaseInfo;
import com.ruoyi.student.domain.StudentRecommendInfo;
import com.ruoyi.student.mapper.StudentBaseInfoMapper;
import com.ruoyi.student.mapper.StudentRecommendInfoMapper;
import com.ruoyi.student.service.IStudentRecommendInfoService;
import com.ruoyi.system.domain.vo.StudentRecommendCompletionStatus;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


@Service
public class StudentRecommendInfoServiceImpl implements IStudentRecommendInfoService {

    @Resource
    private StudentRecommendInfoMapper studentRecommendInfoMapper;


    @Resource
    private StudentBaseInfoMapper studentBaseInfoMapper;


    /**
     * 查询学生推荐表
     *
     * @param id 学生推荐表主键
     * @return 学生推荐表
     */
    @Override
    public StudentRecommendInfo selectStudentRecommendInfoById(Long id) {
        return studentRecommendInfoMapper.selectStudentRecommendInfoById(id);
    }

    /**
     * 查询学生推荐表
     *
     * @param code
     * @return
     */
    @Override
    public StudentRecommendInfo selectStudentRecommendInfoByCode(String code) {
        return studentRecommendInfoMapper.selectStudentRecommendInfoByCode(code);
    }

    /**
     * 查询学生推荐表列表
     *
     * @param studentRecommendInfo 学生推荐表
     * @return 学生推荐表
     */
    @Override
    public List<StudentRecommendInfo> selectStudentRecommendInfoList(StudentRecommendInfo studentRecommendInfo) {
        return studentRecommendInfoMapper.selectStudentRecommendInfoList(studentRecommendInfo);
    }

    /**
     * 新增学生推荐表
     *
     * @param studentRecommendInfo 学生推荐表
     * @return 结果
     */
    @Override
    public int insertStudentRecommendInfo(StudentRecommendInfo studentRecommendInfo) {
        studentRecommendInfo.setCreateTime(DateUtils.getNowDate());
        return studentRecommendInfoMapper.insertStudentRecommendInfo(studentRecommendInfo);
    }

    /**
     * 修改学生推荐表
     *
     * @param studentRecommendInfo 学生推荐表
     * @return 结果
     */
    @Override
    public int updateStudentRecommendInfo(StudentRecommendInfo studentRecommendInfo) {
        studentRecommendInfo.setUpdateTime(DateUtils.getNowDate());
        return studentRecommendInfoMapper.updateStudentRecommendInfo(studentRecommendInfo);
    }

    /**
     * 批量删除学生推荐表
     *
     * @param ids 需要删除的学生推荐表主键
     * @return 结果
     */
    @Override
    public int deleteStudentRecommendInfoByIds(Long[] ids) {
        return studentRecommendInfoMapper.deleteStudentRecommendInfoByIds(ids);
    }

    /**
     * 删除学生推荐表信息
     *
     * @param id 学生推荐表主键
     * @return 结果
     */
    @Override
    public int deleteStudentRecommendInfoById(Long id) {
        return studentRecommendInfoMapper.deleteStudentRecommendInfoById(id);
    }


    /**
     * 更新辅导员审核状态
     *
     * @param code   学生学号
     * @param status 审核状态
     * @return
     */
    @Override
    public int updateStudentRecommendCounsellorCheck(String code, String status) {
        LambdaUpdateWrapper<StudentRecommendInfo> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        lambdaUpdateWrapper.eq(StudentRecommendInfo::getCode, code);
        lambdaUpdateWrapper.set(StudentRecommendInfo::getCounselorRecommendCheck, status);
        return studentRecommendInfoMapper.update(null, lambdaUpdateWrapper);
    }


    /**
     * 填写学生推荐表所在系意见
     *
     * @param code    学号
     * @param opinion 意见
     * @return
     */
    @Override
    public int fillStudentRecommendDepartmentOpinion(String code, String opinion) {
        LambdaUpdateWrapper<StudentRecommendInfo> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        lambdaUpdateWrapper.eq(StudentRecommendInfo::getCode, code);
        lambdaUpdateWrapper.set(StudentRecommendInfo::getDepartmentOpinion, opinion);
        return studentRecommendInfoMapper.update(null, lambdaUpdateWrapper);
    }


    /**
     * 查询各系推荐表完成情况
     *
     * @param year 所属毕业年份
     * @return
     */
    public List<StudentRecommendCompletionStatus> selectStudentRecommendCompletionStatus(String year) {
        return studentRecommendInfoMapper.selectStudentRecommendCompletionStatus(year);
    }

    /**
     * 根据辅导员编号查询推荐表采集数量
     *
     * @param year
     * @param counsellorCode
     * @return
     */
    public Long selectRecommendCollectCountByCounsellorCode(String year, String counsellorCode) {
        return studentRecommendInfoMapper.selectRecommendCollectCountByCounsellorCode(year, counsellorCode);
    }


    /**
     * 根据辅导员编号查询推荐表审核数量
     *
     * @param year
     * @param counsellorCode
     * @return
     */
    public Long selectRecommendCheckCountByCounsellorCode(String year, String counsellorCode) {
        return studentRecommendInfoMapper.selectRecommendCheckCountByCounsellorCode(year, counsellorCode);
    }
}
